<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/11/7
  Time: 16:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>
<%@ page import="com.wsu.search.tools.Tools" %>

<%
   //取得url带过来的参数
    String vrgoodsidVal = Tools.RmNull(request.getParameter("vrgoodsid"));
 
%>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>发布寄售</title>

</head>
<body class="bcf" ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc cf f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
    	发布寄售
    </div>
</div>

<div id="listContainer" class="container db jz mgt45 w100">
  	<section id="saleTab" class="saleTab flexBox bcf f15">
		<div class="flexCenter">
			<span class="current" id="0">寄售</span>
		</div>
		<div class="flexCenter">
			<span id="1">采购</span>
		</div>
	</section>
	
	<section class="w100 b-b">
		<div class="w92 jz df c3 f14 mgt10">
			<img src="mb/images/icon_jishou_num.png" alt="" style="width: 16px;">
			<p class="mgl10">发布数量</p>
			<input id="num" type="num" placeholder="请输入发布数量" class="saleInput db">
		</div>
	</section>
	<section class="w100 b-b">
		<div class="w92 jz df c3 f14 mgt10">
			<img src="mb/images/icon_jishou_rmb.png" alt="" style="width: 16px;">
			<p class="mgl10">发布单价</p>
			<input id="price" type="num" placeholder="请输入发布金额" class="saleInput db">
		</div>
	</section>
	
	<section class="w92 jz mgt10"  style="background:#FFF4EE;border:1px solid #FA8035;">
		<div class="w92 jz c6 f14 lh2">
			<h4 class="orange2">注意事项：</h4>
			<p>1、一旦发布无法手动撤回</p>
			<p id="textTab">2、上架后如寄售不成交，3天后自动撤回</p>
		</div>
	</section>
	
	<section class="w100 mgt10 pdt10">
		<button onclick="javascript:salePost();" class="w92 jz db btnBlue cf f17" style="height:40px;line-height:40px;">发布</button>
	</section>
</div>

<script>
	var typeVal = 0;/* 0出售 1购买 */
	
    $(document).ready(function(){
		
		//getData();
	  	tabFunc($("#saleTab span"),"current",$("#textTab"));
	});

function salePost(){
	var numVal = $("#num").val();
	var priceVal = $("#price").val();
	
	var text = $("#saleTab span.current").text();
 		if(text == "寄售"){
 			typeVal=0;
 		}else if(text == "采购"){
 			typeVal=1;
 		}
	
	if(numVal!="" && priceVal!=""&&numVal!=0 && priceVal!=0){
		 $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m:3010,num:numVal,type:typeVal,price:priceVal,vrgoodsid:<%=vrgoodsidVal%>}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
                if (data.state == 1) {
					 showToast(data.info);
					 setTimeout(' window.history.back()', 1600);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
	
	}else{
		if(numVal==""&&priceVal!=""){
			showToast("请输入发布数量");
		}else if(numVal!=""&&priceVal==""){
			showToast("请输入发布单价");
		}else if(numVal==0 || priceVal==0){
			showToast("发布数量或者发布单价均不可为零!");
		}else{
			showToast("请输入发布数量和发布单价");
		}
		 
	}

}



 function tabFunc(div,klass,textDiv){
 	div.click(function(){
 		div.removeClass(klass);
 		$(this).addClass(klass);
 		var text = $(this).text();
 		if(text == "寄售"){
 			textDiv.text("2、上架后如寄售不成交，3天后自动撤回");
 		}else if(text == "采购"){
 			textDiv.text("2、发布立即上架，3天后自动下架");
 		}
 	});
 }
//加载新数据
 
</script>

</body>
</html>
